package com.hbzhit.modules.sys.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbzhit.common.extension.BaseController;
import com.hbzhit.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import com.hbzhit.modules.sys.entity.ProReportEntity;
import com.hbzhit.modules.sys.service.ProReportService;

import javax.annotation.Resource;

/**
 * 项目填报表
 *
 * @author hbzhit
 * @date 2022-04-26 14:52:48
 */
@Api(tags = {"项目填报表"})
@AllArgsConstructor
@RestController
@RequestMapping("sys/proReport")
public class ProReportController extends BaseController<ProReportService, ProReportEntity> {
    @Resource
    private ProReportService proReportService;

    @ApiOperation("查询填报审批列表数据")
    @GetMapping("/getApprovalList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportGroupId", value = "填报分组id", required = true),
            @ApiImplicitParam(name = "proId", value = "项目id", required = true)
    })
    public R<?> approvalList(@RequestParam String reportGroupId, @RequestParam String proId) {
        if (StrUtil.isEmpty(reportGroupId)) R.error("项目目前还没有填报任务！");
        return R.ok(proReportService.approvalList(reportGroupId, proId));
    }

    @ApiOperation("推送填报测试")
    @GetMapping("/pushTheReport")
    public R pushTheReport() {
        proReportService.pushTheReport();
        return R.ok();
    }

    @ApiOperation("获取项目填报时间列表")
    @GetMapping("/getMarkList")
    public R<?> getMarkList(@RequestParam Long proId) {
        if (ObjectUtil.isEmpty(proId)) return R.error("参数错误！");
        return R.ok().data(proReportService.queryMarkList(proId));
    }


    @ApiOperation("提交/保存填报")
    @PostMapping("/approvalProcess")
    @ApiImplicitParam(name = "status", value = "0-保存填报，1-提交审批", required = true)
    public R<?> approvalProcess(@RequestBody ProReportEntity proReport, @RequestParam Integer status) {
        return R.ok().data(proReportService.approvalProcess(proReport.getId(), status, proReport.getScheduleTasks(), proReport.getCompleteTasks()));
    }

    @ApiOperation("查看待办/已办数据")
    @GetMapping("/queryProReportPage")
    @ApiImplicitParam(name = "status", value = "0-待办，1-已办", required = true)
    public R<?> queryProReportPage(@RequestParam Integer limit, @RequestParam Integer page, @RequestParam Integer status) {
        return R.ok().data(proReportService.proReportPage(new Page(page, limit), status));
    }
}
